#include "VertexIndexSupport.h"

VertexIndexSupport::VertexIndexSupport(int size):m_Indices(3),m_IdInVertexBuffer(0)
{
	// store the original vertex index, texcoord index & normal index
	m_Indices.reserve(size);
}

VertexIndexSupport::~VertexIndexSupport(void)
{
}

bool VertexIndexSupport::SetSemanticIndex(unsigned short index, unsigned short indexValue)
{
	//if ( index < m_Indices.size()){
		m_Indices[index]=indexValue;
		return true;
	//}else
	//	return false;
}

unsigned short VertexIndexSupport::GetSemanticIndex(unsigned short index){
	return m_Indices[index];
}

bool VertexIndexSupport::operator<(const VertexIndexSupport& toCompare)const{
	vector<unsigned short>::const_iterator itThis,itToCompare;
	for ( itThis = m_Indices.begin(), itToCompare = toCompare.m_Indices.begin();
		itThis != m_Indices.end() && itToCompare != toCompare.m_Indices.end();
		++itThis, ++itToCompare)
	{
		unsigned short thisIndex = *itThis;
		unsigned short toCompareIndex = *itToCompare;
		if (thisIndex < toCompareIndex)
			return true;
		else if (thisIndex > toCompareIndex)
			return false;
	}
	
	return false;
}

bool VertexIndexSupport::Equals( VertexIndexSupport* toCompare) const{
	if ( toCompare == NULL )
		return false;
	vector<unsigned short>::const_iterator itThis,itToCompare;
	for ( itThis = m_Indices.begin(), itToCompare = toCompare->m_Indices.begin();
		itThis != m_Indices.end() && itToCompare != toCompare->m_Indices.end();
		++itThis, ++itToCompare)
	{
		unsigned short thisIndex = *itThis;
		unsigned short toCompareIndex = *itToCompare;
		if (thisIndex != toCompareIndex)
			return false;
	}
	return true;
}

size_t VertexIndexSupport::hash()const{
	size_t result=0;
	//vector<unsigned short>::const_iterator itThis;
	
	
	for (size_t i = 0 ; i< m_Indices.size();++i)
	{
		result ^= m_Indices[i];
	}
	return result;
}